package com.ysu.zyw.fk.security;

import com.ysu.zyw.common.constant.SystemConst;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.CachingSessionDAO;

import java.io.Serializable;

/**
 * SessionDao is use for shiro to persist session, this must be an stable session storage,
 * otherwise we provide an redis cache of session, shiro will first search cache, if failed,
 * then go for SessionDao, in this way we let this impl do nothing, all session storage is
 * provided by cache.
 * <p>
 * Created by ZeRur on 2016/1/17.
 *
 * @author yaowu.zhang
 */
public class SessionDao extends CachingSessionDAO {

    @Override
    public String getActiveSessionsCacheName() {
        return SystemConst.CacheNames.ACTIVE_SESSIONS_CACHE_NAME;
    }

    @Override
    protected void doUpdate(Session session) {
        // do nothing
    }

    @Override
    protected void doDelete(Session session) {
        // do nothing
    }

    @Override
    protected Serializable doCreate(Session session) {
        // when we impl an caching session dao, we take care of generate session id mission.
        Serializable sessionId = generateSessionId(session);
        assignSessionId(session, sessionId);
        return sessionId;
    }

    @Override
    protected Session doReadSession(Serializable sessionId) {
        // do nothing
        return null;
    }

}
